﻿using System;
using SrBBSPro.Util;
using System.Collections.Generic;
using SrBBSPro.Entities;
using SrBBSPro.BaseClasses;

namespace SrBBSPro.Services
{
    public class ProMemberService : BaseDoubleService<ProMember>
    {
        public List<ProMember> GetMemberList(long pid, int page, out int count)      
           =>GetLimitList(DbBase.Query<ProMember>()
               .Include(p => p.User).Where(p => p.Id == pid)
               .OrderBy(p=> p.Role).OrderBy(p => p.No).ToList(),out count, page);

        public List<User> GetMembers(long pid)
            => DbBase.Fetch<User>("select * from Users where Id In (select No from ProMember where Id=@0)",pid);

        public int HasManager()
            => DbBase.Query<ProMember>().Count(p => p.Role=="4");

        public Project GetProject(long pid)
            => DbBase.Query<Project>().SingleOrDefault(p =>p.Id==pid);


        public int IsMember(long pid, string sno)
            => DbBase.Single<int>("select count(*) from ProMember where Id=@0 And [No] =@1",pid,sno);

    }
}